package io.renren.modules.wmstate.controller;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import com.fasterxml.jackson.core.JsonProcessingException;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.wmstate.entity.WeldingmachineStateEntity;
import io.renren.modules.wmstate.service.WeldingmachineStateService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2022-08-18 00:07:54
 */
@RestController
@RequestMapping("wmstate/weldingmachinestate")
public class WeldingmachineStateController {
    @Autowired
    private WeldingmachineStateService weldingmachineStateService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("wmstate:weldingmachinestate:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = weldingmachineStateService.queryPage(params);

        return R.ok().put("page", page);
    }


    //弹窗获取设备属性等信息
    @GetMapping("listMachineInfo")
    public String listMachineInfo(@RequestParam("collModelCode") String collModelCode) throws JsonProcessingException {
        return weldingmachineStateService.getMachineList(collModelCode);
    }

    //统计status=1或status=2的数量
    @GetMapping("countStatus")
    public String countStatus() throws JsonProcessingException {
        return weldingmachineStateService.countStatus();
    }

    //获取最近10条焊机的记录


    @GetMapping("listData")
    public String listData(@RequestParam("gwsn") String gwsn,@RequestParam("startDate") String startDate) throws JsonProcessingException {
        return weldingmachineStateService.listData(gwsn,startDate);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{wmNo}")
    @RequiresPermissions("wmstate:weldingmachinestate:info")
    public R info(@PathVariable("wmNo") Integer wmNo){
		WeldingmachineStateEntity weldingmachineState = weldingmachineStateService.getById(wmNo);

        return R.ok().put("weldingmachineState", weldingmachineState);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("wmstate:weldingmachinestate:save")
    public R save(@RequestBody WeldingmachineStateEntity weldingmachineState){
		weldingmachineStateService.save(weldingmachineState);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("wmstate:weldingmachinestate:update")
    public R update(@RequestBody WeldingmachineStateEntity weldingmachineState){
		weldingmachineStateService.updateById(weldingmachineState);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("wmstate:weldingmachinestate:delete")
    public R delete(@RequestBody Integer[] wmNos){
		weldingmachineStateService.removeByIds(Arrays.asList(wmNos));

        return R.ok();
    }

}
